#json 模块
#import json
import time

#转换成json  ----序列化
#中文以unicode的形式展示
# data=[{"id":123,"name":"小峰"},3]
# res=json.dumps(data)
# print(res)
#中文的正常显示
# ret=json.dumps(data,ensure_ascii=False)
# print(ret)

#转换成python数据类型  ----反序列化
# data='[{"id": 123, "name": "\u5c0f\u5cf0"}, 3]'
# res=json.loads(data)
# print(type(data))
# print(res,type(res))


# import json
# from flask import Flask
# app = Flask(__name__)
#
# def index():
#     return "首页"
#
# def users():
#     data = [
#         {"id": 1, "name": "武沛齐", "age": 18},
#         {"id": 2, "name": "alex", "age": 18},
#     ]
#     return json.dumps(data)
#
#
# app.add_url_rule('/index/', view_func=index, endpoint='index')
# app.add_url_rule('/users/', view_func=users, endpoint='users')
#
# if __name__ == '__main__':
#     app.run()

# import json
# import requests
#
# url = "https://movie.douban.com/j/search_subjects?type=movie&tag=%E7%83%AD%E9%97%A8&sort=recommend&page_limit=5&page_start=20"
#
# res = requests.get(
#     url=url,
#     headers={
#         "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
#     }
# )
#
# # json格式
# print(res.text)
#
# # json格式转换为python数据类型
# data_dict = json.loads(res.text)
# print(data_dict)
#
# for item in data_dict['subjects']:
#     print(item)


#json.load --读取文件中的数据并反序列化为python的数据类型（不常用）
# json.dump---向文件中的数据并序列化为json的数据类型（不常用）
# data=[{"id":123,"name":"小峰"},3]
# file_object = open('test.json','w',encoding="utf-8")
# json.dump(data,file_object)
# file_object.close()

# file_object = open('test.json','r',encoding="utf-8")
# data=json.load(file_object)
# file_object.close()
# print(data,type(data))


#time 和  datetime模块
#时间分为本地时间和世界时间

#time
#获取当前时间
"""v1=time.time() 
print(v1)
print(time.timezone/60/60)#获取时区，默认得到的是秒
"""
#让程序暂停
"""print("开始")
time.sleep(5)
print("结束")"""

#datetime
#获取本地时间
from datetime import datetime, timezone, timedelta
"""print(datetime.now())
print(datetime.utcnow())"""
#获取指定时区的时间
"""t=timezone(timedelta(hours=6))
print(datetime.now(t))"""
#时间的加减
"""v1=datetime.now()
v2=v1+timedelta(hours=23)
print(v2)
v=v2-v1
print(v.days,v.seconds,v.microseconds)
"""
#字符串
# text="2024-1-11"
# v=datetime.strptime(text,"%Y-%m-%d")
# print(v)

# v=datetime.now()
# s=v.strftime("%Y-%m-%d %H:%M:%S")
# print(s,type(s))

#时间戳转化

#时间戳转换为datetime类型
"""ctime=time.time()
print(ctime)
t=datetime.fromtimestamp(ctime)
print(t)"""

#将datetime类型转换为时间戳
"""v=datetime.now()
print(v)
v1=v.timestamp()
print(v1)"""

